package com.example.customeview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
 * @author Caleb_F
 * @description:
 * @date :2020-09-24 14:26
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyDemoHolder> {
    private Context mContext;
    private List<String> mlist;

    public MyAdapter(Context mContext, List<String> mlist) {
        this.mContext = mContext;
        this.mlist = mlist;
    }

    @NonNull
    @Override
    public MyDemoHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        MyDemoHolder myDemoHolder = new MyDemoHolder(LayoutInflater.from(mContext).inflate(R.layout.recycler_item, parent,
                false));
        return myDemoHolder;
    }
    //将list中的数据展示到列表中

    @Override
    public void onBindViewHolder(@NonNull MyDemoHolder holder, int position) {
        holder.myCustomeText.setText(mlist.get(position));
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    class MyDemoHolder extends RecyclerView.ViewHolder {
        TextView myCustomeText;
        public MyDemoHolder(@NonNull View itemView) {
            super(itemView);
            myCustomeText = (TextView) itemView.findViewById(R.id.my_custome_text);
        }
    }
}
